package com.guanzhi.mp.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guanzhi.mp.bo.UserJsonBo;
import com.guanzhi.mp.constant.UserEnable;
import com.guanzhi.mp.mapper.UserMapper;
import com.guanzhi.mp.po.UserPo;
import com.guanzhi.mp.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * Mybatis-Plus 练习
 * <p> Package: com.guanzhi.mp.service.impl </p>
 * <p> File: UserServiceImpl.java </p>
 * <p> Description:  (接口服务实现类)</p>
 * <p> Date: 2024/6/16 14:54</p>
 *
 * @author 观之
 * @version 1.0 （代码版本）
 * @email <a href="mailto:guanzhi55634@aliyun.com">观之</a>（邮箱）
 * @date 2024/6/16 14:54
 * @since jdk17（jdk版本）
 */
@Service
@RequiredArgsConstructor
public class UserServiceImpl implements UserService {

    private final UserMapper userMapper;

    @Override
    public void logicDelete() {
        userMapper.deleteById(-776357821800034626L);
    }

    @Override
    public void addUser() {
        UserPo userPo = new UserPo();
        userPo.setId(UUID.randomUUID().getMostSignificantBits());
        userPo.setName("什瓦拉");
        userPo.setEmail("shiwala@1663.con");
        userPo.setPhone("400-1156-9529");
        userPo.setIsDelete(0);
        userPo.setIsEnable(UserEnable.ENABLE);
        userPo.setInfo(new UserJsonBo());
        userMapper.insert(userPo);
    }

    @Override
    public List<UserPo> getAll() {
        return userMapper.selectList(null);
    }

    @Override
    public List<UserPo> getUserByPage(Integer pageNum, Integer pageSize) {
        // 分页
        Page<UserPo> poPage = new Page<>(pageNum, pageSize);

        //执行分页查询
        Page<UserPo> userPoPage = userMapper.selectPage(poPage, null);

        //得到分页结果
        return userPoPage.getRecords();
    }
}
